//
//  WHFishSpotDetailFV.m
//  WHEasyBizLink
//
//  Created by ShengMeng on 9/25/25.
//

#import "WHFishSpotDetailFV.h"
#import "WHFishSpotModel.h"
#import "UIView+Rounded.h"
#import "SDAutoLayout.h"
#import "myUILabel.h"

@interface WHFishSpotDetailFV ()

@property (nonatomic, weak)UIButton*phoneBtn;

@property (nonatomic, weak)UIButton*chatBtn;

@property (nonatomic, weak)UIButton*playBtn;

@property (nonatomic, weak)UIButton*payBtn;


@end

@implementation WHFishSpotDetailFV


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithHexString:@"#767676" alpha:0.1];
        //1.创建控件
        [self createUIControls];
        //2.设置样式(布局)
        [self setUpUIControlsLayout];
    }
    return self;
}

-(void)createUIControls
{
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    phoneBtn.frame = CGRectMake(0, 0, 80, 60);//实际想要宽度80
    phoneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    phoneBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    phoneBtn.tag = 1;
    [phoneBtn setTitle:@"联系钓场" forState:UIControlStateNormal];
    [phoneBtn setTitleColor:[UIColor colorWithHexString:@"#767676" alpha:1.0] forState:UIControlStateNormal];
    [phoneBtn setImage:[UIImage imageNamed:@"dianhua"] forState:UIControlStateNormal];
    [phoneBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self centerButton:phoneBtn];
    phoneBtn.frame = CGRectMake(0, 0, 80, 60);//重新设置一遍
    _phoneBtn = phoneBtn;
    [self addSubview:phoneBtn];
    
    UIButton *chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    chatBtn.frame = CGRectMake(0, 0, 80, 60);//实际想要宽度80
    chatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    chatBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [chatBtn setTitle:@"钓场沟通" forState:UIControlStateNormal];
    [chatBtn setTitleColor:[UIColor colorWithHexString:@"#767676" alpha:1.0] forState:UIControlStateNormal];
    [chatBtn setImage:[UIImage imageNamed:@"news_default"] forState:UIControlStateNormal];
    [chatBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self centerButton:chatBtn];
    chatBtn.frame = CGRectMake(0, 0, 80, 60);//重新设置一遍
    _chatBtn = chatBtn;
    chatBtn.tag = 2;
    [self addSubview:chatBtn];
    
    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    playBtn.frame = CGRectMake(0, 0, 80, 60);//实际想要宽度80
    playBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    playBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [playBtn setTitle:@"直播" forState:UIControlStateNormal];
    [playBtn setTitleColor:[UIColor colorWithHexString:@"#767676" alpha:1.0] forState:UIControlStateNormal];
    [playBtn setImage:[UIImage imageNamed:@"live_default"] forState:UIControlStateNormal];
    [playBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self centerButton:playBtn];
    playBtn.frame = CGRectMake(0, 0, 80, 60);//重新设置一遍
    _playBtn = playBtn;
    playBtn.tag = 3;
    [self addSubview:playBtn];
    
    UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    payBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    payBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [payBtn setTitle:@"立即购票" forState:UIControlStateNormal];
    [payBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payBtn.backgroundColor =whBlueColor;
    payBtn.tag = 4;
    _payBtn = payBtn;
    [self addSubview:payBtn];
    
}

- (void)centerButton:(UIButton *)button{
    button.backgroundColor = [UIColor clearColor];
    CGSize imageSize = button.imageView.frame.size;
    CGSize titleSize = button.titleLabel.frame.size;
    
    button.titleEdgeInsets = UIEdgeInsetsMake(8, -imageSize.width, -imageSize.height -15, 0);
    button.imageEdgeInsets = UIEdgeInsetsMake(-titleSize.height -5, 0, 0, -titleSize.width);
}


- (void)setUpUIControlsLayout
{
    _phoneBtn
        .sd_layout
        .leftSpaceToView(self,10)
        .topSpaceToView(self, 10)
        .widthIs(80)
        .heightIs(40);
    
    _chatBtn
        .sd_layout
        .leftSpaceToView(_phoneBtn,0)
        .topSpaceToView(self, 10)
        .widthIs(80)
        .heightIs(40);
    
    _playBtn
        .sd_layout
        .leftSpaceToView(_chatBtn,0)
        .topSpaceToView(self, 10)
        .widthIs(80)
        .heightIs(40);
    
    _payBtn
        .sd_layout
        .leftSpaceToView(self.playBtn,10)
        .topSpaceToView(self, 10)
        .widthIs(120)
        .heightIs(40);
    
    _payBtn.layer.cornerRadius = 20;
}   
-(void)selecetBtnClick:(UIButton*)btn
{
    if ([_delegate respondsToSelector:@selector(wHFishSpotDetailFVBtnClick:)]) {
        [_delegate wHFishSpotDetailFVBtnClick:btn];
    }

}

@end
